package Controllers 
{
	import Components.ScoreDisplay;
	import ChopperGame;
	import flash.geom.Vector3D;
	import nl.jorisdormans.phantom2D.ai.statemachines.StateMachine;
	import nl.jorisdormans.phantom2D.objects.GameObject;
	import Powerups.GravityLow;
	import States.IdleState;
	import Powerups.FastPowerup;
	import Powerups.SlowPowerup;
	import Powerups.GravityHigh;
	import Powerups.GravityLow;
	/**
	 * ...
	 * @author Sebastiaan
	 */
	public class PowerupController extends GameObject
	{
		private var score : int;
		
		private var randomScore : int;
		public function PowerupController() 
		{
			randomScore = Math.ceil(Math.random() * 400) + 200;
		}
		
		override public function update(elapsedTime:Number):void 
		{
			super.update(elapsedTime);
			score = ScoreDisplay.score;
			if (score == randomScore)
			{
				selectPowerup();
			}	
		}
		
		
		private function selectPowerup() : void
		{
			var random : int = Math.random() * 5 + 1;
			switch(random)
			{
				case 1: ChopperGame.powerupChoose = 1;
						randomize();
						break;
						
				case 2: ChopperGame.powerupChoose = 2;
						randomize();
						break;
						
				case 3: ChopperGame.powerupChoose = 3;
						randomize();
						break;
				
				case 4: ChopperGame.powerupChoose = 4;
						randomize();
						break;
						
				case 5: selectPowerup();
						//ChopperGame.powerupChoose = 5;
						//randomize();
						break;
			}
		}
		
		private function randomize() : int
		{
			if (score < 1200)
			{
				return randomScore = Math.ceil(Math.random() * 1200) + 200;
			}
			else if(score > 1200 && score < 2400)
			{
				return randomScore = Math.ceil(Math.random() * 2400) + 1200;
			}
			else if (score > 2400 && score < 3600)
			{
				return randomScore = Math.ceil(Math.random() * 3600) + 2400;
			}
			else if (score > 3600 && score < 4800)
			{
				return randomScore = Math.ceil(Math.random() * 4800) + 3600;
			}
			else if (score > 4800 && score < 6000)
			{
				return randomScore = Math.ceil(Math.random() * 6000) +4800;
			}
			else if (score > 6000 && score < 7200)
			{
				return randomScore = Math.ceil(Math.random() * 7200) +6000;
			}
			else if (score > 7200 && score < 8400)
			{
				return randomScore = Math.ceil(Math.random() * 8400) +7200;
			}
			else if (score > 8400 && score < 9600)
			{
				return randomScore = Math.ceil(Math.random() * 9200) +8400;
			}
			
			var random : int = Math.ceil(Math.random() * 6000) + 200;
			return random;
		}
	}
}